package com.umanji.user.service;

import java.util.List;


import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import com.umanji.enterprise.domain.Enterprises;
import com.umanji.generic.service.GenericService;
import com.umanji.security.domain.Users;
import com.umanji.user.domain.Members;

@Service("umanjiUserService")
@Transactional(propagation=Propagation.SUPPORTS, readOnly=true)
public class MemberServiceImpl extends GenericService<Members, Long> implements MemberService {

	private final Log log = LogFactory.getLog ( MemberServiceImpl.class );
	
	@Override
	public Object findname(String userok) {
		System.out.println("######################################  ::"+em.createQuery("select count(t) from "+Users.class.getSimpleName()+" t where t.username = :userok").setParameter("userok", userok).getSingleResult());
		return  super.em.createQuery("select count(t) from "+Users.class.getSimpleName()+" t where t.username = :userok").setParameter("userok", userok).getSingleResult().toString();
    }
	
	@Override
	public Object userfindIdCount(String name, Integer jumin1, Integer jumin2) {				
			return  super.em.createQuery("select count(u) from "+Members.class.getSimpleName()+" t join t.user u join fetch t.address where t.realName = :real_name and t.juminNum1 = :jumin_num1 and t.juminNum2 = :jumin_num2").setParameter("real_name", name).setParameter("jumin_num1", jumin1).setParameter("jumin_num2", jumin2).getSingleResult();		
    }

	@Override
	public Object userfindPwCount(String name, Integer jumin1, Integer jumin2, String userid) {				
		return  super.em.createQuery("select count(u) from "+Members.class.getSimpleName()+" t join t.user u join fetch t.address where t.realName = :real_name and t.juminNum1 = :jumin_num1 and t.juminNum2 = :jumin_num2 and u.username = :username").setParameter("real_name", name).setParameter("jumin_num1", jumin1).setParameter("jumin_num2", jumin2).setParameter("username", userid).getSingleResult();		
	}
	
	@Override
	public Object userfindId(String name, Integer jumin1, Integer jumin2) {
			return  super.em.createQuery("select u.username from "+Members.class.getSimpleName()+" t join t.user u join fetch t.address where t.realName = :real_name and t.juminNum1 = :jumin_num1 and t.juminNum2 = :jumin_num2").setParameter("real_name", name).setParameter("jumin_num1", jumin1).setParameter("jumin_num2", jumin2).getSingleResult();		
	}
	
	@Override
	public Object userfindPw(String name, Integer jumin1, Integer jumin2, String userid) {
			return  super.em.createQuery("select u.password from "+Members.class.getSimpleName()+" t join t.user u join fetch t.address where t.realName = :real_name and t.juminNum1 = :jumin_num1 and t.juminNum2 = :jumin_num2 and u.username = :username").setParameter("real_name", name).setParameter("jumin_num1", jumin1).setParameter("jumin_num2", jumin2).setParameter("username", userid).getSingleResult();				
	}




}
